# -*- coding: utf-8 -*-
# @Time    : 2020/3/18 10:48
# @Author  : Weymouth
# @Email   : 261229090@qq.com
# @File    : 计算器.py
# @Software: PyCharm
# ---------------------------------------------------

import re
source = '1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )'

def check(s):
    flag = True
    if re.findall('[a-zA-Z]','s'):
        print('Invalid')
        flag = False
    return flag

def format(s):
    s = s.replace(' ','')
    s = s.replace('++','+')
    s = s.replace('-+','-')
    return s

def cal_mul_div(s):#(2+5*3)
    ret1 = re.search('\d+\.?\d*\[*/]\d+\.?\d*',s).group()
    # x,y = re.split('[*/]','ret')
    #if */
    ret2 = float(x) / float(y)
    str(ret)
    s.replace(ret1,ret2)
    return s

def cal_add_sub(s):

    return (17)

if check(source):
    strs = format(source)


    while re.search('\('):
        strs = re.search('\([^()]\)',strs).group()
        strs = cal_mul_div(strs)
        strs = cal_add_sub(strs)#'(17)'strs[1:-1]
    else:
        strs = cal_mul_div(strs)
        strs = cal_add_sub(strs)  # '(17)'strs[1:-1]

fmt = format()
